﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FoneBuddy.LinqModel.Data;
using FoneBuddy.LinqModel;
using FoneBuddy.LinqData;
public partial class Merchant_List : System.Web.UI.Page
{

    IDataRepository _dataObject = new DataRepository();
    private Int32 Id;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            getMerchants();
    }
    private void getMerchants()
    {
        Merchant merchant = new Merchant();
        List<Merchant> merchants = new List<Merchant>();
        merchant = new Merchant(_dataObject);

        merchants = merchant.GetActive();

        if (merchants != null)
        {
            rptMerchant.DataSource = merchants;
            rptMerchant.DataBind();
        }
    }
    //protected void OnView(object sender, EventArgs e)
    //{
    //    LinkButton lnk = sender as LinkButton;

    //    Merchant merchant = new Merchant(_dataObject);
    //    merchant.Id = Convert.ToInt32(lnk.CommandArgument);
    //    merchant.GetMerchantById();
    //    lblBusinessName.InnerText = merchant.BusinessName;
    //    lblLastLoginDate.Text = merchant.LastLoginDate.ToString();
    //    lblEmailId.Text = merchant.Email;

    //    Address address = new Address(_dataObject);
    //    address.MerchantId = Convert.ToInt32(lnk.CommandArgument); ;
    //    List<Address> addresses = address.GetAddressByMerchantId();
    //    //rptAddress.DataSource = addresses;
    //    //rptAddress.DataBind();

    //    SubscriptionHistory subHistory = new SubscriptionHistory(_dataObject);
    //    List<SubscriptionHistory> subHistories = new List<SubscriptionHistory>();
    //    subHistory.MerchantId = Convert.ToInt32(lnk.CommandArgument); ;
    //   subHistories= subHistory.GetSubscriptionHistoryByMerchantId();
    //   lblSubscription.Text = subHistories.ElementAt(0).Subscription.PlanName;
    //   lblStartDate.Text = subHistories.ElementAt(0).StartDate.ToString("dd/MM/yyyy");
    //   lblOldExpiryDate.Text = subHistories.ElementAt(0).ExpiryDate.ToString("dd/MM/yyyy");
    //   lblDuration.Text = subHistories.ElementAt(0).Subscription.Duration + " Month";
    //}
    [System.Web.Services.WebMethod]
    public static string[] LoadInfo(Int32 Id)
    {
        string[] a = new string[14];
        IDataRepository _dataObject = new DataRepository();
        Merchant merchant = new Merchant(_dataObject);
        merchant.Id = Id;
        merchant.GetMerchantById();

        //lblBusinessName.InnerText = merchant.BusinessName;
        //lblLastLoginDate.Text = merchant.LastLoginDate.ToString();
        //lblEmailId.Text = merchant.Email;
        a[0] = merchant.BusinessName;
        a[1] = merchant.LastLoginDate.ToString();
        a[2] = merchant.Email;


        Address address = new Address(_dataObject);
        address.MerchantId = Id;
        List<Address> addresses = address.GetAddressByMerchantId();
        a[3] = addresses.ElementAt(0).Address1;
        a[4] = addresses.ElementAt(0).Address2;
        a[5] = addresses.ElementAt(0).City.Name;
        a[6] = addresses.ElementAt(0).Pincode;
        //rptAddress.DataSource = addresses;
        //rptAddress.DataBind();

        SubscriptionHistory subHistory = new SubscriptionHistory(_dataObject);
        List<SubscriptionHistory> subHistories = new List<SubscriptionHistory>();
        subHistory.MerchantId = Id;
        subHistories = subHistory.GetSubscriptionHistoryByMerchantId();
        //lblSubscription.Text = subHistories.ElementAt(0).Subscription.PlanName;
        //lblStartDate.Text = subHistories.ElementAt(0).StartDate.ToString("dd/MM/yyyy");
        //lblOldExpiryDate.Text = subHistories.ElementAt(0).ExpiryDate.ToString("dd/MM/yyyy");
        //lblDuration.Text = subHistories.ElementAt(0).Subscription.Duration + " Month";
        a[7] = subHistories.ElementAt(0).Subscription.PlanName; ;
        a[8] = subHistories.ElementAt(0).StartDate.ToString("dd/MM/yyyy");
        a[9] = subHistories.ElementAt(0).ExpiryDate.ToString("dd/MM/yyyy");
        a[10] = subHistories.ElementAt(0).Subscription.Duration + " Month";
        a[11] = merchant.LastLoginDate.ToString();
        a[12] = merchant.Name;
        a[13] = merchant.Mobile;
        //a[14] = Array; // Visitors
        //a[15] = Array; // Clicks
       
        return a;

    }
}